package com.yaoli.Proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * Created by siemens on 6/1/2017.
 */
public class CountJDKProxy implements InvocationHandler {
    private Object object;
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object res;
        System.out.println("begin");
        res = method.invoke(object,args);
        System.out.println("end");

        return res;
    }

    public Object bind(Object object){
        this.object = object;
        return Proxy.newProxyInstance(object.getClass().getClassLoader(),object.getClass().getInterfaces(),this);
    }
}
